<?php


class BankController extends Controller
{
  /**
   * 试卷
   * @param int $id
   */
  public function actionView($id = 0)
  {
    $this->iCheck();
    $this->render('/site/bank/view', array(
        'id' => $id
    ));
  }

  /**
   * ajax 加载试卷...
   * @param int $id
   */
  public function actionExam($id = 0)
  {
    $check = QuestionBankService::instance()->checkExam($id);
    if($check === true){
      $exam = QuestionBankService::instance()->getExam($id);
      $this->renderPartial('/site/bank/exam',array(
          'data'=>$exam
      ));
    }else{
      echo $check;
    }
  }

  /**
   * 试题处理
   */
  public function actionPost()
  {
    if(Yii::app()->request->isPostRequest){
      $bank_id = $_POST['bank_id'];
      unset($_POST['bank_id']);
      $result = QuestionBankService::instance()->getResult($bank_id,$_POST);
      if(is_numeric($result)){
        $this->success('您的测试成绩['.$result.']');
      }else{
        $this->error($this->getError($result),500);
      }
    }else{
      $this->error('非法请求!',400);
    }
  }

  /**
   * 试题列表
   * @param string $keywords
   */
  public function actionList($keywords = '')
  {
    $bank = QuestionBankService::instance()->getList(20,true,false,0,$keywords);
    $this->render('/site/bank/list', array(
        'bank' => $bank
    ));
  }
} 